<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<body class="laytp-container">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title">选择工人花名册信息</span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button class="layui-btn layui-btn-sm btn-dark marginr5" type="button" id="submit">确定</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>


<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">姓名</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">身份证号</label>
                        <div class="layui-input-block">
                            <input type="text" name="idcard" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">联系电话</label>
                        <div class="layui-input-block">
                            <input type="text" name="tel" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">用工性质：</label>
                        <div class="layui-input-block">
                            <select id="yongxing" name="yongxing" lay-filter="yongxing">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">工种</label>
                        <div class="layui-input-block">
                            <div id="gongtype" class="xmselect_div">
                                <div class="xmselect_title">请选择</div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">班组</label>
                        <div class="layui-input-block">
                            <input type="text" name="banid_name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">工资类型：</label>
                        <div class="layui-input-block">
                            <select id="gonglei" name="gonglei" lay-filter="gonglei">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">所在地区</label>
                        <div class="layui-input-block">
                            <input type="text" name="areas" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">开户行</label>
                        <div class="layui-input-block">
                            <input type="text" name="bankname" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">银行卡号</label>
                        <div class="layui-input-block">
                            <input type="text" name="banknum" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    // 单选多选分类 默认单选 choose_type传值为多选
    var choose_type = getQueryVariable('choose_type');
    if(choose_type === undefined || choose_type === false){
        choose_type = 'radio';
    }else{
        choose_type = 'checkbox';
    }


    var parent_dom = getQueryVariable('dom');
    var parent_page = getQueryVariable('page');

    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;

        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        $("#cols_table").hide();
        $("#export_table").hide();
        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_opt_get_labour_gong),where: {}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: ['', '', ''],filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,parseData: function(res){

                var yongxing_str = '<option value="">请选择</option>';
                var yongxing = res.data.yongxing;
                for (var key in yongxing){
                    if(res.data.is_yongxing == yongxing[key]){
                        yongxing_str += '<option value="'+yongxing[key]+'" selected>'+yongxing[key]+'</option>';
                    }else {
                        yongxing_str += '<option value="'+yongxing[key]+'">'+yongxing[key]+'</option>';
                    }

                }
                $("#yongxing").html(yongxing_str);

                xmselect_dan('gongtype', res.data.gongtype, res.data.is_gongtype, function (res) {
                    setTimeout(function () {
                        searchTableFunc(form, table);
                    },100)
                })

                var gonglei_str = '<option value="">请选择</option>';
                var gonglei = res.data.gonglei;
                for (var key in gonglei){
                    if(res.data.is_gonglei == gonglei[key]){
                        gonglei_str += '<option value="'+gonglei[key]+'" selected>'+gonglei[key]+'</option>';
                    }else {
                        gonglei_str += '<option value="'+gonglei[key]+'">'+gonglei[key]+'</option>';
                    }

                }
                $("#gonglei").html(gonglei_str);
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            ,cols: [[
                {type:choose_type,fixed:'left'}
                ,{type:'numbers',title:'序号',fixed:'left'}
                ,{field: 'name', title: '姓名'}
                ,{field: 'idcard', title: '身份证号'}
                ,{field: 'sex', title: '性别'}
                ,{field: 'tel', title: '联系电话'}
                ,{field: 'yongxing', title: '用工性质'}
                ,{field: 'gongtype', title: '工种'}
                ,{field: 'banid_name', title: '班组'}
                ,{field: 'gonglei', title: '工资类型'}
                ,{field: 'gongfee', title: '工价'}
                ,{field: 'areas', title: '所在地区'}
                ,{field: 'bankname', title: '开户行'}
                ,{field: 'banknum', title: '银行卡号'}
            ]]
            ,done : function(res, curr, count){
                $(".layui-table-tool").remove()
                soulTable.render(this);
            }
        });

        table.on('tool(datalist)',function (obj) {
            var data = obj.data;
            if(obj.event === 'get_show_pagess'){
                openPage('../'+data.modenum+'/show.php?id='+data.mid, '80%', '80%');
            }
        });

        listTableSearch(form, table);


        $('#submit').on('click', function () {
            var checkStatus = layui.table.checkStatus('datalist');
            var data = checkStatus.data;
            if(data.length < 1){
                facade.error("请选择数据");return false;
            }

            if(parent_page == 'labour_ban'){
                console.log(data)
                for (var key in data){
                    var str = '<button type="button" style="width: auto;max-width: 95%;" class="layui-btn layui-btn-sm btn-dark" key="'+data[key].id+'">'+data[key].name+
                        '<span class="choose_close" onclick="choose_close(this, \''+parent_dom+'\')">×</span></button>';
                    $("#"+parent_dom , parent.document).append(str);
                }

                // 样式处理
                var h = $("#"+parent_dom , parent.document).height();
                $("."+parent_dom , parent.document).css('cssText','height:'+ (h+5) +'px !important');

                parent.formValid(parent_dom);
            }else{
                var str = '<button type="button"' +
                    'class="layui-btn layui-btn-sm btn-dark" key="'+data[0].id+'"><span class="choose_content">'+data[0].name+'' +
                    '</span><span class="choose_close" onclick="choose_close(this, \''+parent_dom+'\')">×</span></button>';

                $("#"+parent_dom , parent.document).html(str);
                parent.formValid(parent_dom);

            }

            layer_close();
        });

    });
</script>
</body>
</html>
